package com.iwhalecloud.uncc.scheduler;

import com.iwhalecloud.uncc.common.ArchiverConstant;
import com.iwhalecloud.uncc.common.ArchiverThreadLocal;
import com.iwhalecloud.uncc.domain.ArchiveParam;
import com.iwhalecloud.uncc.properties.ArchiverProperties;
import com.iwhalecloud.uncc.web.service.InstantService;
import com.iwhalecloud.uncc.web.service.ScheduleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zq
 * @date 2021/10/9 14:28
 * @description 后台配置调度类
 */
@Component
@Slf4j
public class DaemonScheduler {

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private InstantService instantService;

    @Autowired
    private ArchiverProperties archiverProperties;

    /**
     * 后台配置线程 归档对象ALL
     */
    public void run(){
        ArchiveParam archiveParam = new ArchiveParam();
        archiveParam.setTarget(ArchiverConstant.ALL);
//        archiveParam.setTarget(ArchiverConstant.INS_COLLECT_TASK);
//        archiveParam.setTarget(ArchiverConstant.INS_COLLECT_SERVER);
//        archiveParam.setTarget(ArchiverConstant.INS_COLLECT_SERVICE);
        archiveParam.setNumber(archiverProperties.getNumber());
        archiveParam.setEachInsLines(archiverProperties.getEachInsLines());
        archiveParam.setStartDate(archiverProperties.getStartDate());
        archiveParam.setEndDate(archiverProperties.getEndDate());
        archiveParam.setCron(archiverProperties.getCron());
        archiveParam.setIsDeleteOnline(archiverProperties.getIsDeleteOnline());
        ArchiverThreadLocal.setArchiveParam(archiveParam);
        scheduleService.archiveAll();
        
//        scheduleService.archiveInsCollectTask();
//        scheduleService.archiveInsCollectServer();
//        scheduleService.archiveInsCollectService();

        if (log.isInfoEnabled()){
            log.info("Target: "+archiveParam.getTarget());
            log.info("Number: "+archiveParam.getNumber());
            log.info("OneSendMax: "+archiverProperties.getOneSendMax());
            log.info("EachInsLines: "+archiveParam.getEachInsLines());
            log.info("StartDate: "+archiveParam.getStartDate());
            log.info("EndDate: "+archiveParam.getEndDate());
            log.info("Cron: "+archiveParam.getCron());
            log.info("IsDeleteOnline: "+archiveParam.getIsDeleteOnline());
            log.info("dbNumber.online: "+archiverProperties.getOnlineDbNum());
            log.info("dbNumber.history: "+archiverProperties.getHistoryDbNum());
        }
    }
}
